/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAOImpl;

import DAO.IBaseDAO;
import Util.DBUtils;
import java.math.BigDecimal;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class BaseImpl implements IBaseDAO {

    @Override
    public boolean insert(Object obj) {
        try{
            Connection con =  DBUtils.getConnection();
            
            String query = " SELECT * FROM Production.Location ";
            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

            ResultSet rs = stmt.executeQuery(query);

            //Move cursor to the insert-row
            rs.moveToInsertRow();

            //Set values for insert row
            rs.updateString("Name", "Martin");
            rs.updateBigDecimal(3,new BigDecimal(10.00));
            rs.updateDouble(4, new Double(12.40));

            //Commit append new row in resultSet
            rs.insertRow();

           //Move to the previous row
            rs.moveToCurrentRow();

        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public boolean update(Object obj) {
        try{
            Connection con =  DBUtils.getConnection();
            
            String query = "SELECT * FROM Sales.Store WHERE [Name] LIKE 'O%'";
            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

            ResultSet rs = stmt.executeQuery(query);

            //Move to first row for cusor
            rs.first();

            //Update data n-order column in the first row
            rs.updateString("Name", "Obtain - Mr.Martin");

            //Commit the row updation
            rs.updateRow();

        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }

    @Override
    public boolean delete(Object obj) {
        try{
            Connection con =  DBUtils.getConnection();
            
            String query = " SELECT * FROM Student ";
            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

            ResultSet rs = stmt.executeQuery(query);

            //Move to first row for cusor
            rs.last();

            //Commit the row deletion
            rs.deleteRow();
            
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }

        return true;
    }

    
}
